package com.gzx.plugin.data.wxjk.sync.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.gzx.plugin.data.wxjk.sync.dao.DdzwxxDao;
import com.gzx.plugin.data.wxjk.sync.pojo.Ddzwxx;
import com.gzx.plugin.data.wxjk.sync.service.DdzwxxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
@DS("data")
public class DdzwxxServiceImpl implements DdzwxxService {


    @Autowired
    private DdzwxxDao ddzwxxDao;


    @Override
    @Transactional
    public Boolean save(String req) {

        Boolean flag = false;
        try {
            JSONObject reqData = JSON.parseObject(req);
            String data = reqData.getString("accountDataInfo");
            List<Ddzwxx> list = JSON.parseObject(data, List.class);
            log.info("订单账务信息更新当前批次数据到数据库，总数:{}条", list.size());
            ddzwxxDao.batchSave(list);
            flag = true;
        } catch (Exception e) {
            log.error("订单账务信息接口保存失败");
            throw new RuntimeException(e);
        }
        return flag;
    }
}
